<include file="public/header"/>
<style>
    .form-required{color: red}
</style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInUp">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <if condition="$Request.action eq 'add'">
                        <h5>创建用户</h5>
                        <else/>
                        <h5>编辑用户</h5>
                    </if>

                    <div class="ibox-tools">
                        <!--<a href="{:url('Menu/index')}" class="btn btn-primary btn-xs">后台菜单</a>
                        <a href="#" class="btn btn-primary btn-xs active">添加菜单</a>
                        <a href="{:url('Menu/lists')}" class="btn btn-primary btn-xs">所有菜单</a>-->
                    </div>
                </div>
                <div class="ibox-content">
                    <if condition="$Request.action eq 'add'">
                        <form class="form-horizontal js-ajax-form" action="{:url('add')}" method="post">
                        <else/>
                        <form class="form-horizontal js-ajax-form" action="{:url('privateUpdate',array('id'=>$data.id))}" method="post">
                    </if>
                    <div class="form-group">
                        <div class="col-sm-1"></div>
                        <label class="col-sm-1 control-label"><span class="form-required">*</span>客户姓名</label>
                        <div class="col-md-3">
                            <input type="text" class="form-control" id="input-name" name="pub[name]" required value="{$data.name ?? ''}">
                        </div>

                        <label class="col-sm-1 control-label"><span class="form-required">*</span>性别</label>
                        <div class="col-md-3">
                            <div class="radio i-checks">
                                <label>
                                    <input type="radio" value="1" name="pub[sex]" checked> <i></i> 男</label>
                                <input type="radio" value="0" name="pub[sex]"> <i></i> 女</label>
                            </div>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <div class="col-sm-1"></div>
                        <label class="col-sm-1 control-label"><span class="form-required">*</span>联系方式</label>
                        <div class="col-md-3">
                            <input type="text" class="form-control" id="input-phone" name="pub[phone]" required value="{$data.phone ?? ''}">
                        </div>

                        <label for="input-age" class="col-sm-1 control-label">年龄</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control" id="input-age" name="pub[age]" required value="{$data.age ?? ''}">
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <div class="col-sm-1"></div>
                        <label class="col-sm-1 control-label"><span class="form-required">*</span>客户意向</label>
                        <div class="col-md-3">
                            <select name="pub[yixiang]" id="yixiang" class="form-control">
                                <option value="-1">--请选择客户意向--</option>
                                <option value="A">关键客户</option>
                                <option value="B">重要客户</option>
                                <option value="C">普通客户</option>
                                <option value="D">一般客户</option>
                                <option value="E">死客</option>
                                
                            </select>
                        </div>
                        <label class="col-sm-1 control-label"><span class="form-required">*</span>客户等级</label>
                        <div class="col-md-3">
                            <select name="pub[level]" id="level" class="form-control">
                                <option value="-1">--请选择客户等级--</option>
                                <option value="1">普通客户</option>
                                <option value="2">普通员工</option>
                                <option value="3">公司高管</option>
                                <option value="4">VIP</option>
                            </select>
                        </div>

                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <div class="col-sm-1"></div>
                        <label class="col-sm-1 control-label">客户行业</label>
                        <div class="col-md-3">
                            <input class="form-control" id="input-hangye" name="pub[hangye]" value="{$data.hangye ?? ''}"/>
                        </div>
                        <label class="col-sm-1 control-label">客户来源</label>
                        <div class="col-md-3">
                            <div class="radio i-checks">
                                <label><input type="radio" value="1" name="pub[from]" checked> <i></i> 个人查找</label>
                                <label><input type="radio" value="2" name="pub[from]"> <i></i> 主动联系</label>
                                <label><input type="radio" value="3" name="pub[from]"> <i></i> 公司派单</label>
                            </div>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <div class="col-sm-1"></div>
                        <label class="col-sm-1 control-label"><span class="form-required">*</span>地址</label>
                        <div class="col-md-2">
                            <select name="pub[prov]" id="province" class="form-control" onchange="getRegion(this.value,1)" >
                                <option value="-1">请选择地址</option>
                                <volist name="province" id="vo">
                                    <option value="{$vo.code}">{$vo.name}</option>
                                </volist>
                            </select>
                        </div>
                        <div class="col-sm-2">
                            <select name="pub[city]" id="city" class="form-control" onchange="getRegion(this.value,2)">
                                <if condition="$Request.action eq 'privateupdate'">
                                    <volist name="city" id="vo">
                                        <option value="{$vo.code}">{$vo.name}</option>
                                    </volist>
                                </if>
                            </select>
                        </div>
                        <div class="col-sm-3">
                            <select name="pub[area]"  class="form-control" id="area">
                                <if condition="$Request.action eq 'privateupdate'">
                                <volist name="area" id="vo">
                                <option value="{$vo.code}">{$vo.name}</option>
                                </volist>
                                </if>
                            </select>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <div class="col-sm-1"></div>
                        <label class="col-sm-1 control-label"><span class="form-required">*</span>详细地址</label>
                        <div class="col-md-7">
                            <input type="text" class="form-control" id="input-address" name="pub[address]" required value="{$data.address ?? ''}">
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <div class="col-sm-1"></div>
                        <label class="col-sm-1 control-label">备注</label>
                        <div class="col-md-7">
                            <textarea class="form-control" id="input-content" name="pub[content]">{$data.content ?? ''}</textarea>
                        </div>
                    </div>

                    <div class="hr-line-dashed"></div>

                       <div class="form-group">
                           <div class="col-sm-2"></div>
                           <div class="col-sm-2">
                               <a class="help-block m-b-none" id="dianji_box" style="cursor: pointer;color: #F56A6F;"><i class="fa fa-info-circle"></i> 点击填写公司信息</a>
                           </div>
                        </div>
                    <div class="companyBox" style="display: none;">
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <div class="col-md-1"></div>
                        <label class="col-sm-1 control-label">公司名称</label>
                        <div class="col-md-3">
                            <input type="text" class="form-control" id="input-comp-name" name="comp[name]"  value="{$comp.name ?? ''}">
                        </div>
                        <label class="col-sm-1 control-label">公司电话</label>
                        <div class="col-md-3">
                            <input type="text" class="form-control" id="input-comp-phone" name="comp[phone]"  value="{$comp.phone ?? ''}">
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <div class="col-sm-1"></div>
                        <label class="col-sm-1 control-label">公司地址</label>
                        <div class="col-md-7">
                            <input type="text" class="form-control" id="input-comp-address" name="comp[address]"  value="{$comp.address ?? ''}">
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <div class="col-md-1"></div>
                        <label class="col-sm-1 control-label">公司行业</label>
                        <div class="col-md-3">
                            <input type="text" class="form-control" id="input-comp-hangye" name="comp[hangye]"  value="{$comp.hangye ?? ''}">
                        </div>
                        <label class="col-sm-1 control-label">公司邮编</label>
                        <div class="col-md-3">
                            <input type="text" class="form-control" id="input-comp-code" name="comp[code]"  value="{$comp.code ?? ''}">
                        </div>
                    </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <div class="col-sm-4 col-sm-offset-2">
                            <input type="hidden" name="comp_id" value="{$data.comp_id ?? ''}">
                            <button class="btn btn-primary" type="submit">保存内容</button>
                            <button type="button" class="btn btn-default" onclick="javascript:history.back(-1);" >返回</button>
                        </div>
                    </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="__TMPL__/public/assets/js/jquery.min.js?v=2.1.4"></script>
<script src="__TMPL__/public/assets/js/bootstrap.min.js?v=3.3.5"></script>
<script src="__TMPL__/public/assets/js/content.min.js?v=1.0.0"></script>
<script src="__TMPL__/public/assets/js/plugins/iCheck/icheck.min.js"></script>
<script>
    $(document).ready(function(){
        $(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});
        $('#dianji_box').click(function(){
            $('.companyBox').slideToggle('slow');
            $('.companyBox').css('display','block');
        });
        $("[name='pub[yixiang]']").find("[value='{$data.yixiang ?? '-1'}']").attr("selected", true);
        $("[name='pub[level]']").find("[value='{$data.level ?? '-1'}']").attr("selected", true);
        $("[name='pub[prov]']").find("[value='{$data.prov ?? '-1'}']").attr("selected", true);
        $("[name='pub[city]']").find("[value='{$data.city ?? '-1'}']").attr("selected", true);
        $("[name='pub[area]']").find("[value='{$data.area ?? '-1'}']").attr("selected", true);
        $("[name='pub[from]'][value='{$data.from ?? '1'}']").attr("checked", true);
        $("[name='pub[sex]'][value='{$data.sex ?? '1'}']").attr("checked", true);
    });

    function getRegion(val,level) {
        var $city = $("#city");
         var $area = $("#area");
         if (level == '1') {
             $city.html('<option value=""> --请选择市-- </option>');
             $city.val('');
         }
         $area.html('<option value=""> --请选择区-- </option>');
         $area.val('');
         $.post('{:url("admin/common/getRegion")}', {pcode: val, level: level}, function (data) {
             var dataObj = eval("(" + data + ")");
             if (dataObj['code'] == 1) {
                 if (level == '1') {
                     $.each(dataObj['list'], function (i, item) {
                         $city.append('<option value="' + item['code'] + '">' + item['name'] + '</option>');
                     });
                 } else {
                     $.each(dataObj['list'], function (i, item) {
                         $area.append('<option value="' + item['code'] + '">' + item['name'] + '</option>');
                     });
                 }
             }
         });
    }
</script>
<script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
</body>
</html>